package net.sycu.wj.ems.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sycu.wj.ems.business.DepartmentService;
import net.sycu.wj.ems.business.LoginLogService;
import net.sycu.wj.ems.business.LoginService;
import net.sycu.wj.ems.business.NoteService;
import net.sycu.wj.ems.dao.LoginLogDao;
import net.sycu.wj.ems.entity.LoginBean;
import net.sycu.wj.ems.entity.LoginLogBean;
import net.sycu.wj.ems.entity.LoginLogSearcher;
import net.sycu.wj.ems.entity.NoteBean;
import net.sycu.wj.ems.entity.NoteSearcher;

public class HeaderServlet extends BaseServlet {
	NoteService service = new NoteService();
	DepartmentService departmentService = new DepartmentService();
	LoginService loginService = new LoginService();
	LoginLogService loginLogService = new LoginLogService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String sortString = "SendDateTime DESC";
		NoteSearcher searcher = new NoteSearcher();
		LoginLogSearcher loginLogSearcher = new LoginLogSearcher();
		LoginBean login = this.getLogin();
		loginLogSearcher.getLogin().setLoginId(login.getLoginId());
		loginLogSearcher.getLogin().setLoginName(login.getLoginName());

		ArrayList<LoginLogBean> loginLogs = loginLogService.search(loginLogSearcher, "LoginDateTime DESC");
		searcher.setSendDateTimeBegin(loginLogs.get(0).getLoginDateTime());
		searcher.setSendDateTimeEnd(new Timestamp(System.currentTimeMillis()));
		ArrayList<NoteBean> notes = service.searchForAccept(this.getLogin().getLoginId(),searcher,sortString);
		request.setAttribute("notes", notes);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
